Validator = {
Require : /.+/,
Require_ : /[^%]/,
Email : /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/,
Phone : /^((\(\d{3}\))|(\d{3}\-))?(\(0\d{2,3}\)|0\d{2,3}[-]{0,1})?[1-9]\d{6,7}$/,
Mobile : /^((\(\d{3}\))|(\d{3}\-))?1[3,4,5,8]\d{9}$/,
Url : /^(http:\/\/[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"\"])*)|(http:\/\/localhost[\/=\?%\-&_~`@[\]\':+!]*([^<>\"\"])*)$/,
/*IdCard : /^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{4}$/,*/
IdCard : /^((\d{9})|(\d{15})|(\d{17}([Xa-z0-9])))$/,
IdCard_new : /^\d{18}(\d{18}[A-Za-z0-9\*])?$/,
Double_fourdottwo : /^((\d{1,4}\.\d{1,2})|(\d{1,4}))$/,
Currency : /^\d+(\.\d+)?$/,
Number : /^\d+$/,
tel : /^[\d-]{8,30}$/,
bankcardno : /^\d{1,50}$/,
Zip : /^[1-9]\d{5}$/,
QQ : /^[1-9]\d{4,8}$/,
Integer_ : /^[-\+]?\d+$/,
Integer_1 : /^\d+(\.\d{1})$/,
PInteger : /^[+]?\d+$/,
NInteger : /^[-]?\d+$/,
Double : /^[-\+]?\d+(\.\d+)?$/,
Double_0:  /-|^[-\+]?\d+$/,
Double_1 : /-|^[-\+]?\d+(\.\d{1})$/,
Double_2: /^(([0-1]\.\d{1,2})|([0-1]))$/,	 
NDouble_2 : /-|^[-\+]?\d+(\.\d{1,2})?$/,
Double_3 : /-|^[-\+]?\d+(\.\d{1,3})?$/,
Double_4 : /-|^[-\+]?\d+(\.\d{1,4})?$/,
Double_5 : /-|^[-\+]?\d+(\.\d{1})?$/,
Double_6 : /^(([0]\.\d{1,4})|([0,1]))$/,
Double_7 : /^((\d{1,6}\.\d{1,2})|(\d{1,6}))$/,
Double_0_4 : /^(([0]\.\d{1,4})|([0]))$/,
Double_9 : /^((\d{1,6}\.\d{1,2})|(\d{1,4}))$/,
Double_10: /^[-\+]?((\d{1,10}\.\d{1,2})|(\d{0,8}))$/,
Double_11: /^((\d{1,2}\.\d{1,4})|(\d{0,2}))$/,			/** 12.3456	*/	
Double_13: /^((\d{1,2}\.\d{1,2})|(\d{0,2}))$/,			/** 12.34	*/
Double_14: /^(([0-1]\.\d{1,4})|([0-1]))$/,				/** 1.2345	*/	
Double_15 : /^(([-\+]?\d{1,6}\.\d{1,2})|(\d{1,6}))$/,
Double_eightdottwo : /^[-\+]?((\d{1,6}\.\d{1,2})|(\d{1,6}))$/,
Double_16: /^((\d{1,5}\.\d{1,2})|(\d{0,5}))$/,
Double_17 : /^(([0]\.\d{1,2})|([0]))$/,
Double_18: /^[-\+]?((\d{1,5}\.\d{1,2})|(\d{0,5}))$/,
Double_10_2 : /^[-\+]?((\d{1,10}\.\d{1,2})|(\d{1,10}))$/,
Double_10_3 : /^[-\+]?((\d{1,10}\.\d{1,2})|(\d{0,8}))$/,
Double_19 : /^[-\+]?((\d{1,7}\.\d{1,2})|(\d{1,7}))$/,
PNDouble_5_2 : /^[-\+]?((\d{1,5}\.\d{1,2})|(\d{1,3}))$/,
Double_21 : /^[-\+]?((\d{1,3}\.\d{1,2})|(\d{1,3}))$/,
NDouble_7_2 : /(^[-]((\d{1,7}\.\d{1,2})|(\d{1,7})))|(^[0])$/,
PNDouble_7_2 : /^[-\+]?((\d{1,7}\.\d{1,2})|(\d{1,7}))$/,
Double_7_2 : /^((\d{1,7}\.\d{1,2})|(\d{1,7}))$/,
Double_5_2 : /^((\d{1,4}\.\d{1,2})|(\d{1,4}))$/,
Double_5_3: /^((\d{1,5}\.\d{1,2})|(\d{1,5}))$/,
Double_0_2 : /^[-\+]?(([0]\.\d{1,2})|([0]))$/,
PNDouble_4_2 : /^[-\+]?((\d{1,4}\.\d{1,2})|(\d{1,3}))$/,
English : /^[A-Za-z]+$/,
Chinese : /^[\u0391-\uFFE5]+$/,
UnSafe : /^(([A-Z]*|[a-z]*|\d*|[-_\~!@#\$%\^&\*\.\(\)\[\]\{\}<>\?\\\/\'\"]*)|.{0,5})$|\s/,
IsSafe : function(str){return !this.UnSafe.test(str);},
SafeString : "this.IsSafe(value)",
Limit : "this.limit(value.length,getAttribute('min'), getAttribute('max'))",
LimitB : "this.limit(this.LenB(value), getAttribute('min'), getAttribute('max'))",
Date : "this.IsDate(value, getAttribute('min'), getAttribute('format'))",
Repeat : "value == document.getElementsByName(getAttribute('to'))[0].value",
Range : "getAttribute('min') < value && value < getAttribute('max')",
Integer : "this.intRange(value, 0,65536)",
Integer_Range : "this.intRange(value, parseInt(getAttribute('min')),parseInt(getAttribute('max')))",
Compare : "this.compare(value,getAttribute('operator'),getAttribute('to'))",
Custom : "this.Exec(value, getAttribute('regexp'))",
Group : "this.MustChecked(getAttribute('name'), getAttribute('min'), getAttribute('max'))",
ErrorItem : [document.forms[0]],
ErrorMessage : ["以下原因导致提交失败:\t\t\t\t"],
onReadDigitalKey : function(){
	var iekey=event.keyCode; 
	var realkey=event.keyCode;
	
	var obj = event.srcElement;
	if(obj.type=="text"){
		var digitalType = obj.getAttribute("digitalType");
		/**
		**Delete 0-9  (45-56)
		**small board: 0-9 (95-106)
		** <-  -> : (36-41)
		** Delete 46
		** home ,end (35,36)
		** Tab 9
		**/
		var NORMAL_KEY_0		=48;
		var NORMAL_KEY_9		=57;
		
		var SMALL_KEY_0			=96;
		var SMALL_KEY_9			=105;		
		
		var DIRECTION_KEY_LEFT 	=37;
		var DIRECTION_KEY_DOWN	=40;
		
		var NORMALL_KEY_DOT		=190;
		var SMALL_KEY_DOT		=110;
		var NORMAL_KEY_DELETE	=46;
		var NORMAL_KEY_BACK		=8;		 
		
		var NORMAL_KEY_PLUS		=109;		 
		var SMALL_KEY_PLUS		=189;	
		
		var NORMAL_KEY_TAB		=9;		 
		switch(digitalType){
			case "Integer":
			//is 0-9
			    var isTrue = (realkey>=NORMAL_KEY_0 && realkey<=NORMAL_KEY_9) || (realkey>=SMALL_KEY_0 && realkey<=SMALL_KEY_9);	    
	   		    isTrue = isTrue || (realkey==NORMAL_KEY_PLUS || realkey==SMALL_KEY_PLUS);
	   		    isTrue = isTrue || (realkey>=DIRECTION_KEY_LEFT && realkey<=DIRECTION_KEY_DOWN);
	   		    isTrue = isTrue || (realkey==NORMAL_KEY_DELETE);
	   		    isTrue = isTrue || (realkey==NORMAL_KEY_BACK);
	    	    isTrue = isTrue || (realkey==NORMAL_KEY_TAB);
			    
			    if(isTrue){
	//			if(realkey==109 || realkey==9 || realkey==13 || (realkey>34 && realkey<37) || (realkey>45 && realkey<56) || (realkey>95 && realkey<106) || (realkey>36 && realkey<41) || realkey==8 || realkey==110 || realkey==189 || realkey==190){
					//return control name;
					//alert(realkey);
					return true;		
				}else{
					//alert(realkey);
					event.returnValue=false;	
					return false;	
				}
				break;
			case "Double":
			    var isTrue = (realkey>=NORMAL_KEY_0 && realkey<=NORMAL_KEY_9) || (realkey>=SMALL_KEY_0 && realkey<=SMALL_KEY_9);	    
			    isTrue = isTrue || (realkey==NORMALL_KEY_DOT || realkey==SMALL_KEY_DOT);
	   		    isTrue = isTrue || (realkey==NORMAL_KEY_PLUS || realkey==SMALL_KEY_PLUS);
	   		    isTrue = isTrue || (realkey>=DIRECTION_KEY_LEFT && realkey<=DIRECTION_KEY_DOWN);
	   		    isTrue = isTrue || (realkey==NORMAL_KEY_DELETE);
	   		    isTrue = isTrue || (realkey==NORMAL_KEY_BACK);
	    	    isTrue = isTrue || (realkey==NORMAL_KEY_TAB);
			    
			    if(isTrue){
	//			if(realkey==109 || realkey==9 || realkey==13 || (realkey>34 && realkey<37) || (realkey>45 && realkey<56) || (realkey>95 && realkey<106) || (realkey>36 && realkey<41) || realkey==8 || realkey==110 || realkey==189 || realkey==190){
					//return control name;
					if(obj.value.indexOf(".")>=0 && (NORMALL_KEY_DOT==realkey || SMALL_KEY_DOT==realkey)){
						event.returnValue=false;
					}
					//alert(obj.value);
					return true;		
				}else{
					//alert(realkey);
					event.returnValue=false;	
					return false;	
				}
				break;
			default:
		}
	}
},
Validate : function(theForm, mode){

var obj = theForm || event.srcElement;
var count = obj.elements.length;
this.ErrorMessage.length = 1;
this.ErrorItem.length = 1;
this.ErrorItem[0] = obj;
for(var i=0;i<count;i++){
with(obj.elements[i]){
var _dataType = getAttribute("dataType");
if(typeof(_dataType) == "object" || typeof(this[_dataType]) == "undefined") continue;
this.ClearState(obj.elements[i]);
if(getAttribute("require") == "false" && value == "") continue;

switch(_dataType){
case "Date" :
case "Repeat" :
case "Range" :
case "Integer" :
case "Integer_Range" :
case "Compare" :
case "Custom" :
case "Group" : 
case "Limit" :
case "LimitB" :
case "SafeString" :
if(!eval(this[_dataType])) {
this.AddError(i, getAttribute("msg"));
}
break;
default :

if(!this[_dataType].test(value)){
this.AddError(i, getAttribute("msg"));
}
break;
}
}
}
if(this.ErrorMessage.length > 1){
mode = mode || 1;
var errCount = this.ErrorItem.length;
switch(mode){
case 3 :
for(var i=1;i<errCount;i++)
this.ErrorItem[i].style.color = "red";
case 2 :
alert(this.ErrorMessage.join("\n"));
this.ErrorItem[1].focus();
break;
case 1 :
for(var i=1;i<errCount;i++){
try{
var span = document.createElement("span");
span.id = "__ErrorMessagePanel";
span.className = "error";
this.ErrorItem[i].parentNode.appendChild(span);
span.innerHTML = this.ErrorMessage[i].replace(/\d+:/,"");
}
catch(e){alert(e.description);}
}
this.ErrorItem[1].focus();
break;
default :
alert(this.ErrorMessage.join("\n"));
break;
}
return false;
}
return true;
},
intRange:function(v,min,max){
	var r = new RegExp("^[+]?\\d+$");
	if(!r.test(v)){
		return false;
	}
	return min<=v && v<=max;
},
limit : function(len,min, max){
min = min || 0;
max = max || Number.MAX_VALUE;
return min <= len && len <= max;
},
LenB : function(str){
return str.replace(/[^\x00-\xff]/g,"**").length;
},
ClearState : function(elem){
with(elem){
if(style.color == "red")
style.color = "";
var lastNode = parentNode.childNodes[parentNode.childNodes.length-1];
if(lastNode.id == "__ErrorMessagePanel")
parentNode.removeChild(lastNode);
}
},
AddError : function(index, str){
this.ErrorItem[this.ErrorItem.length] = this.ErrorItem[0].elements[index];
this.ErrorMessage[this.ErrorMessage.length] = this.ErrorMessage.length + ":" + str;
},
Exec : function(op, reg){
return new RegExp(reg,"g").test(op);
},
compare : function(op1,operator,op2){
switch (operator) {
case "NotEqual":
return (op1 != op2);
case "GreaterThan":
return (op1 > op2);
case "GreaterThanEqual":
return (op1 >= op2);
case "LessThan":
return (op1 < op2);
case "LessThanEqual":
return (op1 <= op2);
default:
return (op1 == op2); 
}
},
MustChecked : function(name, min, max){
var groups = document.getElementsByName(name);
var hasChecked = 0;
min = min || 1;
max = max || groups.length;
for(var i=groups.length-1;i>=0;i--)
if(groups[i].checked) hasChecked++;
return min <= hasChecked && hasChecked <= max;
},
IsDate : function(op, formatString){
formatString = formatString || "ymd";
var m, year, month, day;
switch(formatString){
case "ymd" :
m = op.match(new RegExp("^((\\d{4})|(\\d{2}))([-./])(\\d{1,2})\\4(\\d{1,2})$"));
if(m == null ) return false;
day = m[6];
month = m[5]--;
year = (m[2].length == 4) ? m[2] : GetFullYear(parseInt(m[3], 10));
break;
case "dmy" :
m = op.match(new RegExp("^(\\d{1,2})([-./])(\\d{1,2})\\2((\\d{4})|(\\d{2}))$"));
if(m == null ) return false;
day = m[1];
month = m[3]--;
year = (m[5].length == 4) ? m[5] : GetFullYear(parseInt(m[6], 10));
break;
default :
break;
}
if(!parseInt(month)) return false;
month = month==12 ?0:month; 
var date = new Date(year, month, day);
return (typeof(date) == "object" && year == date.getFullYear() && month == date.getMonth() && day == date.getDate());
function GetFullYear(y){return ((y<30 ? "20" : "19") + y)|0;}
}
}
